package com.wxb.qd.utils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.wxb.qd.entity.Aerodata;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 实现读取excel
 * @author wangxb
 */
@Data
@Component
public class TableListener extends AnalysisEventListener {
    private List<Aerodata> aerodataList= new ArrayList<>();
    /**
     * 读取后对这些数据做操作
     * @param o
     * @param analysisContext
     */
    @Override
    public void invoke(Object o, AnalysisContext analysisContext) {
        Aerodata aerodata = (Aerodata) o;
        aerodata.setIsDelete(0);
        aerodata.setCreateTime(new Date());
        aerodata.setUpdateTime(new Date());
        aerodata.setIsShare(1);
        aerodataList.add(aerodata);
    }

    /**
     * 操作完成后进行的操作。
     * @param analysisContext
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
//        System.out.println(aerodataList);
        System.out.println("------正在读取------");
    }
}
